home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Franz PD / Franz PD Disk #054 (1990)(Amiga User Group Deutschland e.V.).zip / Franz PD Disk #054 (1990)(Amiga User Group Deutschland e.V.).adf / Bin2Ass / Bin2Ass.s < prev   
Text File  |  1989-07-02  |  10KB  |  428 lines

  1. ;
  2. ; Bin2Ass.s :  konvertiert files in folgendes Format :
  3. ;              " dc.w $aaaa,$bbbb,...,$zzzz ;..A..S.D.."
  4. ;
  5. **************************************************************
  6. *                                                            *
  7. *  THIS IS  PUBLIC DOMAIN  !!!!  Do with it what you like !!!!
  8. *                                                            *
  9. **************************************************************
  10. ;
  11. ;              Autor : Sascha Groening
  12. ;                      Blaustr.:    13
  13. ;                      8360 Deggendorf
  14. ;                      WEST-Germany
  15. ;
  16. ;
  17. ;
  18. ;              fuer A68k   Public Domain Assembler
  19. ;                   BLINK  Public Domain Linker
  20. ;
  21. ;              Aufruf :  AssData [> outfile] infile
  22. ;
  23. ;              Assemblieren :  A68K AssData.s
  24. ;                              BLINK AssData.o
  25. ;
  26. ;
  27. ;
  28.  
  29.  
  30.  
  31. SysBase   equ 4
  32. OldOpenLibrary equ -408
  33. FindTask equ -294
  34. AllocMem equ -198
  35. FreeMem equ -210
  36. CloseLibrary equ -414
  37.  
  38. Open equ -30
  39. Close equ -36
  40. Read equ -42
  41. Write equ -48
  42. Output equ -60
  43. Lock equ -84
  44. UnLock equ -90
  45. Examine equ -102
  46.  
  47. MODE_READWRITE equ 1004
  48. MODE_OLDFILE   equ 1005
  49. MODE_NEWFILE   equ 1006
  50. MODE_READONLY  equ MODE_OLDFILE
  51.  
  52. MEMF_PUBLIC  equ $1
  53. MEMF_CHIP    equ $2
  54. MEMF_FAST    equ $4
  55. MEMF_CLEAR   equ $10000
  56. MEMF_LARGEST equ $20000
  57.  
  58. SHARED_LOCK equ -2
  59.  
  60. fib_DiskKey      equ $00
  61. fib_DirEntryType equ $04
  62. fib_FileName     equ $08
  63. fib_Protection   equ $74
  64. fib_EntryType    equ $78
  65. fib_Size         equ $7c
  66. fib_NumBlocks    equ $80
  67. fib_DateStamp    equ $84
  68. fib_Comment      equ $90
  69. fib_SIZEOF       equ $104
  70.  
  71. tc_sigrecvd      equ 26 ;Eintrag in der Task-Struktur der Process-Struktur
  72.                         ;der die Signal Bits enthaelt (CTRL-C ... CTRL-F)
  73.  
  74. SIGBREAKB_CTRLC  equ 12 ;Bit 12 gesetzt wenn CTRL-C gedrueckt
  75. SIGBREAKB_CTRLD  equ 13
  76. SIGBREAKB_CTRLE  equ 14
  77. SIGBREAKB_CTRLF  equ 15
  78.  
  79.  
  80. CALLEXEC macro
  81.          movea.l SysBase,a6
  82.          jsr    \1(a6)
  83.          endm
  84.  
  85. CALLDOS  macro
  86.          movea.l DOSBase,a6
  87.          jsr    \1(a6)
  88.          endm
  89.  
  90.  
  91. ;
  92. ;  *****  MainProg *****
  93. ;
  94.  
  95. _main
  96.     move.l a7,stapel
  97.     move.l a0,comadr
  98.     move.l d0,comlaenge
  99.     clr.b  -1(a0,d0)        ;Null terminated string
  100.  
  101.     lea.l  dosname,a1
  102.     CALLEXEC OldOpenLibrary ;Open dos.library
  103.     move.l  d0,DOSBase
  104.     beq     fini            ;Was ? Nicht da ?!?! Nix wie raus !!!
  105.  
  106.     CALLDOS Output          ;OutputHandle holen
  107.     move.l  d0,OutHandle
  108.  
  109.     suba.l  a1,a1           ;find own task
  110.     CALLEXEC FindTask
  111.     addi.l #tc_sigrecvd,d0
  112.     move.l d0,tasksigbits   ;adr unserer Signal-Bits
  113.  
  114.  
  115.     move.l comlaenge,d0     ;Filename nicht eingegeben ?
  116.     subq.l #1,d0
  117.     beq.s  helpmessage
  118.  
  119. ;
  120. ; Prglaenge holen
  121. ;
  122.     bsr    getlength   ;wie lang ist das zu ladende File ?
  123. ;
  124. ; Prglaenge ausgeben
  125. ;
  126.  
  127. ;    move.l flaenge,d2
  128. ;    lea.l  hbuf,a0
  129. ;    move.b  #10,8(a0)  ;LineFeed anfuegen
  130. ;    bsr     hexasc     ;in Hex-Zahl wandeln
  131. ;
  132. ;    move.l  OutHandle,d1
  133. ;    move.l  #hbuf,d2
  134. ;    moveq.l  #9,d3
  135. ;    CALLDOS Write
  136. ;
  137. ;**** Speicher belegen ***
  138. ;
  139.     move.l flaenge,d0
  140.     move.l #MEMF_CLEAR!MEMF_PUBLIC,d1 ;allokierten Speicher mit $00 fuellen
  141.     CALLEXEC AllocMem
  142.     move.l d0,DATA            ;nicht genug freier Speicher ?
  143.     beq    nomem
  144. ;
  145. ; File lesen
  146. ;
  147.     bsr readfile
  148. ;
  149. ; File ausgeben
  150. ;
  151.     bsr Display
  152. ;
  153. ; CleanUp
  154. ;
  155.  
  156. CloseAll
  157. memfree
  158.     movea.l stapel,a7
  159.     movea.l DATA,a1
  160.     move.l flaenge,d0
  161.     CALLEXEC  FreeMem
  162.  
  163. unlock
  164.     movea.l stapel,a7
  165.     move.l lock,d1
  166.     CALLDOS UnLock
  167.  
  168. closedos
  169.     movea.l stapel,a7
  170.     movea.l  DOSBase,a1
  171.     CALLEXEC CloseLibrary        ;CloseLibrary
  172.     clr.l   d0
  173. fini    rts
  174.  
  175.  
  176. ****************************************
  177. ; SubProgs
  178.  
  179. helpmessage
  180.     move.l  OutHandle,d1
  181.     move.l  #Fehler1,d2
  182.     moveq.l  #len1,d3
  183.     CALLDOS Write
  184.     bra     closedos
  185.  
  186. nomem
  187.     move.l  OutHandle,d1
  188.     move.l  #Fehler3,d2
  189.     moveq.l  #len3,d3
  190.     CALLDOS Write     ;LVOWrite
  191.     bra     unlock
  192. ;
  193. ; Konvertiere d2.l in ASCII-String ab (a0)
  194. ;
  195.  
  196. hexasc
  197.     moveq.l #3,d0                       ;4 Nibble (=1 Word) wandeln
  198.     adda.l  #8,a0                       ;Pos der letzten Stelle im Buffer+1
  199. loop5
  200.     moveq.l #15,d1                      ;
  201.     and.l   d2,d1                       ;1 Nibble isolieren
  202.     asr.l   #4,d2                       ;naechstes Nibble an 1.Pos
  203.     addi.b  #48,d1                      ;isol. Nibble+48=Zahl in ASCII
  204.     cmpi.b  #57,d1                      ;war Zahl >9 ?
  205.     bls.s   cont4
  206.     addq.l  #7,d1                       ;wenn ja noch 7 dazu ==> A-F
  207. cont4
  208.     move.b  d1,-(a0)                    ;in Buffer eintragen
  209.     dbra    d0,loop5                    ;naechstes Nibble wandeln
  210.     rts
  211.  
  212. ;
  213. ; gibt Speicherinhalt in dc.w $ Form aus
  214. ;
  215.  
  216.  
  217. Display
  218.     move.l flaenge,d5      ;laenge des Files
  219.     movea.l DATA,a3        ;FileBuffer
  220.  
  221. loop2
  222.     lea.l line,a4
  223.     lea.l dcw,a0           ;' dc.w ' in Buffer eintragen
  224.  
  225.     move.l (a0)+,(a4)+
  226.     move.w (a0)+,(a4)+
  227.  
  228.  
  229.     moveq.l #4,d4
  230. loop3
  231.     lea.l dol,a0           ;'$' in Buffer eintragen
  232.     move.b (a0)+,(a4)+
  233.  
  234.     clr.l  d2
  235.     move.w (a3)+,d2        ;naechstes Word holen
  236.     lea.l  hbuf,a0         ;Ziel der Konvertierung
  237.     move.b #32,4(a0)       ;Space anfuegen
  238.     bsr.s  hexasc          ;in Hex-Zahl wandeln
  239.  
  240.     lea.l hbuf+4,a0
  241.     move.b (a0)+,(a4)+
  242.     move.b (a0)+,(a4)+
  243.     move.b (a0)+,(a4)+
  244.     move.b (a0)+,(a4)+
  245.  
  246.     tst.l  d4              ;wenn letztes Word ==> kein Komma darstellen
  247.     beq.s  cont1
  248.  
  249.     lea.l kom,a0           ;',' in Buffer eintragen
  250.     move.b (a0)+,(a4)+
  251.  
  252. cont1
  253.     dbra   d4,loop3        ;naechstes Word in ASCII wandeln
  254.  
  255.     lea.l sem,a0           ;'  ;' in Buffer eintragen
  256.     move.b (a0)+,(a4)+
  257.     move.b (a0)+,(a4)+
  258.     move.b (a0)+,(a4)+
  259.  
  260.  
  261. ;
  262. ; ASCII Ausgabe
  263. ;
  264.  
  265.     suba.l #10,a3          ;Zeiger im Buffer wieder um 5 Words zurueck
  266.  
  267.     moveq.l #9,d4          ;10 Buchstaben darstellen
  268. loop4
  269.     move.b (a3),d0         ;nicht darstellbare Zeichen
  270.     cmpi.b #' ',d0         ;mit Space ueberschreiben
  271.     blt    cont2
  272.     cmpi.b #'z',d0
  273.     blt  cont3
  274. cont2
  275.     move.b #' ',(a3)
  276. cont3
  277.     adda.l #1,a3           ;Pointer = Pointer + 1
  278.     dbra   d4,loop4
  279.  
  280.     suba.l #10,a3
  281.  
  282.     move.l (a3)+,(a4)+
  283.     move.l (a3)+,(a4)+
  284.     move.w (a3)+,(a4)+
  285.  
  286.                            ;10 Byte aus dem Buffer kopieren
  287.                            ;=> ASCII Zeichen als Kommentar
  288.     lea.l  Ret,a0
  289.     move.b (a0)+,(a4)+
  290.  
  291.     move.l OutHandle,d1
  292.     move.l #line,d2
  293.     moveq.l #50,d3
  294.     CALLDOS Write          ;Zeile ausgeben
  295.  
  296.     move.l tasksigbits,a0
  297.     move.l (a0),d0
  298.     btst.w #SIGBREAKB_CTRLC,d0   ;CTRL-C gedrueckt ?
  299.     bne.s  break           ;wenn zustaendiges Bit in
  300.                            ;TaskControlStrktr gesetzt ==> *** Break ***
  301.  
  302.     subi.l #10,d5
  303.     tst.l  d5
  304.     bne    loop2                ;naechste Zeile darstellen
  305.  
  306.     rts
  307.  
  308. ;
  309. ; User-Break detected
  310. ;
  311.  
  312. break
  313.     move.l  OutHandle,d1
  314.     move.l  #Fehler2,d2
  315.     moveq.l #len2,d3
  316.     CALLDOS Write
  317.     bra     CloseAll
  318.  
  319. ;
  320. ; comadr enthaelt pointer auf null-terminated string
  321. ; der den Filenamen enthaelt
  322. ; ==> flaenge enthaelt Laenge des zu ladenden Files
  323. ;     als Vielfaches von 10 (aus programmtechnischen Gruenden)
  324. ;
  325.  
  326. getlength
  327.     move.l comadr,d1
  328.     move.l SHARED_LOCK,d2
  329.     CALLDOS Lock
  330.     move.l d0,lock
  331.     beq    helpmessage
  332.  
  333.                               ;allocate Speicher fuer Fileinfoblock Struktur
  334.     move.l #fib_SIZEOF,d0     ;groesse des Speichers
  335.     move.l #MEMF_CLEAR!MEMF_CHIP,d1 ;allokierten Speicher mit $00 fuellen
  336.     CALLEXEC AllocMem
  337.     move.l d0,FileInfoBlock   ;nicht genug freier Speicher ?
  338.     beq    nomem              ;sicher ist sicher
  339.                               ;fuer zukuenftige abgespeckte Amiga-Versionen
  340.                               ;mit weniger als 128 KByte
  341.  
  342.     move.l lock,d1
  343.     move.l FileInfoBlock,d2
  344.     CALLDOS Examine
  345.  
  346.     move.l FileInfoBlock,a0
  347.     move.l fib_Size(a0),d0    ;Filelaenge holen
  348.     divu.w #10,d0             ;daraus Viefaches von 10 machen
  349.     andi.l #$FFFF,d0  ;Rest der Division loeschen
  350.     mulu.w #10,d0
  351.     addi.l #10,d0     ;ob nun ein Rest aufgetreten ist oder nicht
  352.  
  353.     move.l d0,flaenge
  354.  
  355.     movea.l FileInfoBlock,a1
  356.     move.l #fib_SIZEOF,d0
  357.     CALLEXEC  FreeMem
  358.  
  359.     rts
  360.  
  361. readfile
  362.     move.l comadr,d1
  363.     move.l #MODE_OLDFILE,d2
  364.     CALLDOS Open
  365.     move.l d0,d4  ;braucht nicht getestet werden ob <> 0
  366.                   ;wurde in getlength schon erledigt
  367.  
  368.     move.l d0,d1
  369.     move.l DATA,d2
  370.     move.l flaenge,d3
  371.     CALLDOS Read
  372.  
  373.     move.l d4,d1
  374.     CALLDOS Close
  375.  
  376.     rts
  377.  
  378. ***************************************
  379.  
  380.  
  381.  DATA constants
  382.  
  383.  
  384. dosname     dc.b 'dos.library',0
  385.             cnop 0,4
  386. Fehler1     dc.b 'Bin2Ass   by Sascha Groening',10
  387.             dc.b 'This is Public Domain ! Do with it what you like !!!',10
  388.             dc.b 'Usage "Bin2Ass [>outfile] infile/A" ',10
  389. len1        equ  *-Fehler1
  390.             cnop 0,4
  391. Fehler2     dc.b '*** BREAK ***',10
  392. len2        equ  *-Fehler2
  393.             cnop 0,4
  394. Fehler3     dc.b 'not enough Memory  !',10
  395. len3        equ  *-Fehler3
  396.             cnop 0,4
  397. dcw         dc.b ' dc.w '
  398.             cnop 0,4
  399. kom         dc.b ','
  400.             cnop 0,4
  401. dol         dc.b '$'
  402.             cnop 0,4
  403. Ret         dc.b 10
  404.             cnop 0,4
  405. sem         dc.b '  ;'
  406.             cnop 0,4
  407.  
  408.  
  409.  BSS storage
  410.  
  411.             cnop  0,4
  412. DOSBase       ds.l 1
  413. DATA          ds.l 1
  414. FileInfoBlock ds.l 1
  415. OutHandle     ds.l 1
  416. tasksigbits   ds.l 1
  417. flaenge       ds.l 1
  418. comadr        ds.l 1
  419. comlaenge     ds.l 1
  420. stapel        ds.l 1
  421. lock          ds.l 1
  422. hbuf          ds.l 3
  423. line          ds.b 81
  424.             cnop 0,4
  425.  
  426.             END
  427.  
  428.